package com.cskaoyan.gateway.controller.shopping;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.shopping.PanelDetailService;
import com.mall.shopping.TbItemGoodService;
import com.mall.shopping.dto.CategoryDto;
import com.mall.shopping.dto.GetProductByIdDto;
import com.mall.shopping.dto.GoodRecommendResponse;
import com.mall.shopping.dto.NavigationDto;
import com.mall.user.annotation.Anoymous;
import io.swagger.models.auth.In;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: lin
 * @Date: 2020/7/11 14:45
 */

@RestController
@RequestMapping("shopping")
@Anoymous
public class ShoppingViewController {

    @Reference(check = false)
    PanelDetailService panelDetailService;

    @Reference(check = false)
    TbItemGoodService itemGoodService;

    @GetMapping("homepage")
    public ResponseData homepageHandler(){
        List<GoodRecommendResponse> responses = panelDetailService.getHomePage();
        return new ResponseUtil().setData(responses);
    }

    @GetMapping("navigation")
    public ResponseData navigationHandler(){
        List<NavigationDto> response = panelDetailService.getNavigations();
        return new ResponseUtil().setData(response);
    }

    @GetMapping("categories")
    public ResponseData categoriesHandler(String sort){
        List<CategoryDto> response = itemGoodService.getCategoryList(sort);
        return new ResponseUtil().setData(response);
    }

    @GetMapping("product/{id}")
    public ResponseData productHandler(@PathVariable("id")Integer id){
        GetProductByIdDto response = itemGoodService.getProduct(id);
        return new ResponseUtil().setData(response);
    }

}
